package com.bw.car_module.carlist;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bw.car_module.BR;
import com.bw.car_module.R;
import com.bw.car_module.databinding.FragmentCarBinding;
import com.bw.common.field.EventBusEntity;
import com.bw.common.mvvm.view.BaseFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

@Route(path = "/car/carfragment")
public class CarFragment extends BaseFragment<FragmentCarBinding,CartViewModel> {
    @Override
    public int bindLayout() {
        return R.layout.fragment_car;
    }

    @Override
    public int vrId() {
        return BR.vm;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void syncCart(EventBusEntity entity){
        if (entity.action.equals("refreshCart")){
            vm.syncCart();
        }
    }

}
